﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "调查问卷");
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");

		dateNow = datetimeAdvice.getCurrentDateString();
		
		studentId = sessionAdvice.getAutherUserID();
		studentGrade = sessionAdvice.getUserProp("studentGrade");
		studentDepartment = sessionAdvice.getUserProp("studentDepartment");
		studentGender = sessionAdvice.getUserProp("studentSex");

		sql = "	SELECT
					q.qsn_id,q.title,q.describe,q.date_start,
					q.date_end
				FROM
					t_questionnaire q
				WHERE
						( q.date_start < :dateNow OR q.date_start = :dateNow )
					AND
						( q.date_end > :dateNow OR q.date_end = :dateNow )
					AND
						q.state = '2'
					AND
						(
							(
								( q.grade_allowed = 'ALL' OR q.grade_allowed LIKE :gradeCondition )
								AND
								( q.institute_allowed = 'ALL' OR q.institute_allowed LIKE :instituteCondition )
								AND
								( q.gender_allowed = 'ALL' OR q.gender_allowed LIKE :genderCondition )
							)
							OR
							(
								EXISTS(
									SELECT 0 FROM t_respondents r
									WHERE
									   q.qsn_id = r.qsn_id
									AND
									   r.stu_id = :studentId 
									AND
									   r.state = 'U'
								)
							)
						)";
		
		queryObj = new Query(datasource = application.dnsSlave);

		queryObj.addParam(name="dateNow", value=dateNow, cfsqltype="cf_sql_char");
		queryObj.addParam(name="gradeCondition", value="%" & studentGrade & "%", cfsqltype="cf_sql_varchar");
		queryObj.addParam(name="instituteCondition", value="%" & studentDepartment & "%", cfsqltype="cf_sql_varchar");
		queryObj.addParam(name="genderCondition", value="%" & studentGender & "%", cfsqltype="cf_sql_varchar");
		queryObj.addParam(name="studentId", value=studentId, cfsqltype="cf_sql_varchar");
		
		rs_question = queryObj.execute(sql=sql).getResult();
		
		
		/* 判断当前标签显示 */
		currentTab = event.getArg("TabID", "labQuestionnaire");
		
		passArgs = structNew();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>在线调查
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labQuestionnaire">class="active"</cfif> id="labQuestionnaire" tabTarget="Questionnaire">需回答的问卷</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Questionnaire" class="tabContent">
					
					<div class="noticeBlock">
						<h3>进行中的问卷</h3>
						<p><span class="img icon16x16 message"></span>下面列出的是目前与您相关的调查问卷, 请花费少许时间, 帮助我们完成在线调查.</p>
						<hr/>
					</div>
					
                    <cfif rs_question.recordCount>
						<div class="clearfix">
							<div class="UICardTable">
                                <cfloop query="rs_question">
									<cfset structInsert(passArgs, "QSN", rs_question.qsn_id, true) />
									<cfset sign = encrypt(rs_question.qsn_id, studentId, "PBEWithMD5AndDES", "Hex") />
									<cfset structInsert(passArgs, "ST", sign, true) />
									<dl class="col2">
										<dt>
											<a href="<cfoutput>#buildURL('voteResponse', passArgs)#</cfoutput>" title="<cfoutput>#stringAdvice.HTMLFormEncode( rs_question.describe )#</cfoutput>">
												<em class="questionnaire"><!--imgholder--></em>
												<dd>
													<h3 class="fixed"><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_question.title )#</cfoutput></h3>
													<div>时限:<span><cfoutput>#dateTimeAdvice.formatDateString( rs_question.date_start, 'YYYY/MM/DD' )#</cfoutput> - <cfoutput>#dateTimeAdvice.formatDateString( rs_question.date_end, 'YYYY/MM/DD' )#</cfoutput></span></div>
												</dd>
											</a>
										</dt>
									</dl>
								</cfloop>
							</div>
						</div>
						<cfelse>
						<div class="systemNotice">
							<h3>太棒了</h3>
							<p class="mln">看起来, 您已经完成了目前所有的问卷. 谢谢您花费宝贵的时间帮助我们了解实际状况.</p>
						</div>
					</cfif>
				</div>
			</div>
		</li>
	</ul>
</div>